package mn.asri.teaproc.client;

/** represents a "question" used in a test session. */
public class PocQuestion extends BaseModel {

	public static final int TYPE_MCQ = 0;
	public static final int TYPE_TF = 1;
	public static final int TYPE_ESSAY = 2;
	public static final int TYPE_FOLLOW_UP = 3;

	private String[] responses;
	private PocReferencedObject referencedObject;

	/** patch up the <code>responses</code> before "serializing" into the payload. */
	protected void preStringify() {
		StringBuffer buffer = new StringBuffer();
		for (int i = 0; i < responses.length; i++) {
			buffer.append(responses[i]).append(ARRAY_DELIM);
		}
		setData("responses", buffer.toString());

		setData("referencedObject", referencedObject);
	}

	/**
	 * handle the <code>responses</code> after being "deserialized" from the
	 * payload.
	 */
	protected void postObjectify() {
		String responsesString = getData("responses");
		if (responsesString != null) {
			responses =
				responsesString.split(new String(new char[]{ARRAY_DELIM}));
		}

		String string2 = getData("referencedObject");
		if (string2 != null) {
			referencedObject = new PocReferencedObject();
			referencedObject =
				(PocReferencedObject) toBaseModel(string2, referencedObject);
		}
	}

	public int getIndex() { return toInt(getData("index")); }

	public void setIndex(int index) { setData("index", index + ""); }

	public String getText() { return getData("text"); }

	public void setText(String text) { setData("text", text); }

	public int getType() { return toInt(getData("type")); }

	public void setType(int type) { setData("type", type + ""); }

	public String[] getResponses() {
		return responses;
	}

	public void setResponses(String[] responses) {
		this.responses = responses;
	}

	public PocReferencedObject getReferencedObject() {
		return referencedObject;
	}

	public void setReferencedObject(PocReferencedObject referencedObject) {
		this.referencedObject = referencedObject;
	}

	public long getServerTicks() { return toLong(getData("serverTicks")); }

	public void setServerTicks(long serverTicks) {
		setData("serverTicks", serverTicks + "");
	}
}
